// ##############################
// ####  note:  bokeweilai event main fun
// ####  create:  TANWENHUI (twh:谭文辉)
// ####  date:   2024/6/18
// ##############################

#include "bkwl_common.h"
#include "bkwl_event.h"
#include "bkwl_uart.h"
#include "bkwl_protocol_jiwei.h"

bkwl_err_t bkwl_protocol_jiwei_init()
{
	bkwl_err_t ret = BK_OK;
	tprintf("bkwl_protocol_jiwei_init entry\n");

	tprintf("bkwl_protocol_jiwei_init exit\n");

	return ret;
}

uint32_t bkwl_protocol_jiwei_get_cmd_len(uint8_t cmd, uint8_t *data, uint32_t len)
{
	uint32_t cmd_len = 10;
	switch (cmd)
	{
	case BKWL_CMD_DOOR_START_WIFI_PAIR:
	case BKWL_CMD_DOOR_MESSAGE:
	case BKWL_CMD_DOOR_POWER_OFF:
	case BKWL_CMD_DOOR_CLEAN_DATA:
	case BKWL_CMD_DOOR_GET_DEVICE_INFO:
	case BKWL_CMD_DOOR_UPGRADE:
	case BKWL_CMD_DOOR_PRODUCT_TEST:
	case BKWL_CMD_DOOR_GET_NET_TIME:
	case BKWL_CMD_DOOR_ACK_REMOTE_UNLOCK:
	case BKWL_CMD_DOOR_UPLOAD_IMAGE:
	case BKWL_CMD_DOOR_START_UPLOAD_IMAGE:
	case BKWL_CMD_DOOR_VIDEO_STATUS_NOTIFY:
	case BKWL_CMD_DOOR_VIDEO_PARA_SETUP:
	case BKWL_CMD_DOOR_STATUS_REPORT:
	case BKWL_CMD_DOOR_STOP_WIFI_PAIR:
	case BKWL_CMD_DOOR_DEVICE_FUNC:
	case BKWL_CMD_DOOR_LOOK_SETUP:
	case BKWL_CMD_DOOR_GET_VERSION:
	case BKWL_CMD_DOOR_GET_WEATHER:
	case BKWL_CMD_DOOR_GET_REGION:
	{
		cmd_len = 10;
		break;
	}
	case BKWL_CMD_DOOR_USER_VERIFY:
	{
		if (len >= 4)
			cmd_len = 10 + data[3];
		else
			cmd_len = 10;
		break;
	}

	case BKWL_CMD_DOOR_CACHE_MESSAGE:
	{
		cmd_len = 13;
		break;
	}
	}
	return cmd_len;
}

uint32_t bkwl_protocol_jiwei_get_cmd_handle(uint8_t *data, uint32_t len)
{
	uint32_t ret = 0;
	uint32_t i = 0;
	uint32_t cmd_len = 0;
	// 0xAA 0x55 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 校验和
	uint8_t cmd_buf[11] = {0};
	for (i = 0; i < len - 1; i++)
	{
		if (data[i] == 0xaa && data[i + 1] == 0x55)
		{
			// tprintf("bkwl_protocol_jiwei_get_cmd  aa 55\n");
			cmd_len = bkwl_protocol_jiwei_get_cmd_len(data[i], data + i, len);
			if (len - i >= cmd_len)
			{
				bkwl_err_t check = bkwl_protocol_jiwei_checksum(data + i, cmd_len);
				if (check == BKWL_OK)
				{
					// tprintf("bkwl_protocol_jiwei_get_cmd  cmd \n");
					memcpy(cmd_buf, data + i, cmd_len);
					bkwl_protocol_jiwei_parse(cmd_buf, cmd_len);
					ret = ret + cmd_len;
				}
				else
				{
					tprintf("bkwl_protocol_jiwei_get_cmd error cmd ,i=%d\n", i);
					ret = ret + cmd_len;
				}
			}
			else
			{
				tprintf("bkwl_protocol_jiwei_get_cmd data len not  ok ,cur len=%d\n", len - i);
			}
		}
	}

	return ret;
}

bkwl_err_t bkwl_protocol_jiwei_checksum(uint8_t *data, uint32_t len)
{
	bkwl_err_t ret = BKWL_OK;
	// 数据包:AA 55 01 16 09 00 01 00 00 20
	// 0x20=(0xAA+0x55+0x01+0x16+0x09+0x00+0x01+0x00+0x00)&0xFF
	uint32_t cur_value = 0;
	for (uint8_t i = 0; i < len - 1; i++)
	{
		cur_value = cur_value + data[i];
	}
	uint8_t data_value = data[len - 1];
	uint8_t check_value = (cur_value & 0xff);
	if (data_value != check_value)
	{
		tprintf("bkwl_protocol_jiwei_checksum  BKWL_ERROR ,check_value=0x%x != data_value=0x%x\n", check_value, data_value);
		ret = BKWL_ERROR;
	}

	return ret;
}

bkwl_err_t bkwl_protocol_jiwei_parse(uint8_t *data, uint32_t len)
{
	bkwl_err_t ret = BK_OK;
	bkwl_msg_t msg;

	uint8_t cmd_value = data[2];
	// 0xAA 0x55 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 校验和
	switch (cmd_value)
	{
	case 0x01:
	{
		tprintf("get cmd: BKWL_CMD_DOOR_START_WIFI_PAIR \n");
		// 2.1 配网模式
		// AA 55 01 16 09 00 01 00 00 20
		// AA 55 02 00 01 00 00 00 00 02
		// AA 55 01 16 09 00 01 00 00 20 //失敗
		// AA 55 02 02 01 00 00 00 00 04
		bkwl_door_wifi_pair_t *bkwl_door_wifi_pair = (bkwl_door_wifi_pair_t *)malloc(sizeof(bkwl_door_wifi_pair_t));
		bkwl_door_wifi_pair->type = data[5];
		bkwl_door_wifi_pair->notify = data[7];
		msg.cmd = BKWL_CMD_DOOR_START_WIFI_PAIR;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_wifi_pair;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x03:
	{
		tprintf("get cmd: BKWL_CMD_DOOR_MESSAGE \n");
		// 2.2 消息上传
		// AA 55 03 01 00 01 00 01 00 05
		// AA 55 02 00 03 00 00 00 00 04
		// [17:09:34.319] 主板发送 指令=信息上传(0x03)
		// 串口数据=AA 55 03 01 00 01 00 01 00 05
		// [17:09:35.896] 模块发送 指令=WiFi应答(0x02)
		// 串口数据=AA 55 02 00 03 00 00 00 00 04
		bkwl_door_message_t *bkwl_door_message = (bkwl_door_message_t *)malloc(sizeof(bkwl_door_message_t));
		bkwl_door_message->event = data[3];
		bkwl_door_message->info = data[4];
		bkwl_door_message->user_type = data[5];
		bkwl_door_message->user_num = data[6];
		msg.cmd = BKWL_CMD_DOOR_MESSAGE;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_message;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x04:
	{
		// tprintf("get cmd: BKWL_CMD_DOOR_POWER_OFF \n");
		// 2.3 断电通知
		// AA 55 04 00 00 00 00 00 00 03
		// AA 55 02 00 04 00 00 00 00 05
		// [17:18:16.613] 主板发送 指令=断电通知(0x04)
		// 串口数据=AA 55 04 00 00 00 00 00 00 03
		// [17:18:16.845] 模块发送 指令=WiFi应答(0x02)
		// 串口数据=AA 55 02 00 04 00 00 00 00 05

		bkwl_door_power_off_t *bkwl_door_power_off = (bkwl_door_power_off_t *)malloc(sizeof(bkwl_door_power_off_t));
		bkwl_door_power_off->mode = data[3];
		msg.cmd = BKWL_CMD_DOOR_POWER_OFF;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_power_off;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x05:
	{
		// tprintf("get cmd: BKWL_CMD_DOOR_CLEAN_DATA \n");
		// 2.4 清除数据
		// [17:28:16.613] 主板发送 指令=清除数据(0x05)
		// 串口数据=AA 55 05 00 00 00 00 00 00 04
		// [17:28:17.845] 模块发送 指令=WiFi应答(0x02)
		// 串口数据=AA 55 02 00 05 00 00 00 00 06
		msg.cmd = BKWL_CMD_DOOR_CLEAN_DATA;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x06:
	{
		// 2.5 设备信息
		// [17:38:16.613] 主板发送 指令=读取设备信息(0x06)
		// 串口数据=AA 55 06 00 00 00 00 00 00 05
		// [17:38:16.845] 模块发送 指令=读取设备信息应答(0x02)
		// 串口数据=AA 55 07 32 30 39 46 35 41 35 43 38 44 34 30 5C CF 7F 3E 32 4C 00 00 00 00 00
		// 00 1B

		// tprintf("get cmd: BKWL_CMD_DOOR_GET_DEVICE_INFO \n");
		msg.cmd = BKWL_CMD_DOOR_GET_DEVICE_INFO;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x0a:
	{
		// 2.6 升级固件
		// [17:48:16.613] 主板发送 指令=升级固件(0x0A)
		// 串口数据=AA 55 0A 00 00 00 00 00 00 09
		// [17:49:47.845] 模块发送 指令=升级固件应答(0x0B)
		// 串口数据=AA 55 0B 01 00 00 00 00 00 0B

		// tprintf("get cmd: BKWL_CMD_DOOR_UPGRADE \n");
		msg.cmd = BKWL_CMD_DOOR_UPGRADE;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x0c:
	{
		// 2.7 模块产测
		// [19:35:10.345] 主板发送 指令=模块产测(0x0C)
		// 串口数据=AA 55 0C 00 00 00 00 00 00 0B
		// [19:35:13.485] 模块发送 指令=模块产测应答(0x0D)
		// 串口数据=AA 55 0D 01 00 00 00 00 00 0D

		// tprintf("get cmd: BKWL_CMD_DOOR_PRODUCT_TEST \n");
		msg.cmd = BKWL_CMD_DOOR_PRODUCT_TEST;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x10:
	{
		// 2.8 网络时间
		// 已联网
		// [19:41:24.760] 主板发送 指令=获取网络时间(0x10)
		// 串口数据=AA 55 10 00 00 00 00 00 00 0F
		// [19:41:24.833] 模块发送 指令=网络时间应答(0x11)
		// 串口数据=AA 55 11 67 E9 D4 5E 50 00 E2

		// 未联网
		// [16:57:59.214] 主板发送 指令=获取网络时间(0x10)
		// 串口数据=AA 55 10 00 00 00 00 00 00 0F
		// [16:57:59.341] 模块发送 指令=网络时间应答(0x11)
		// 串口数据=AA 55 11 00 00 00 00 50 00 60

		// tprintf("get cmd: BKWL_CMD_DOOR_GET_NET_TIME \n");
		msg.cmd = BKWL_CMD_DOOR_GET_NET_TIME;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x12:
	{
		// 2.9 远程开锁
		// [10:50:41.136] 主板发送 指令=信息上传(0x03)
		// 串口数据=AA 55 03 03 00 00 00 00 00 05
		// [10:50:50.336] 模块发送 指令=WiFi应答(0x02)
		// 串口数据=AA 55 02 00 00 00 00 00 00 01
		// [10:50:50.543] 模块发送 指令=远程开锁(0x13)
		// 串口数据=AA 55 13 05 00 00 00 00 00 17
		// [10:50:50.559] 主板发送 指令=远程开锁应答(0x12)
		// 串口数据=AA 55 12 00 00 00 00 00 00 11
		// [10:50:50.682] 主板发送 指令=信息上传(0x03)
		// 串口数据=AA 55 03 01 00 05 00 00 00 08
		// [10:50:50.876] 模块发送 指令=WiFi应答(0x02)
		// 串口数据=AA 55 02 00 00 00 00 00 00 01

		// tprintf("get cmd: BKWL_CMD_DOOR_ACK_REMOTE_UNLOCK \n");
		msg.cmd = BKWL_CMD_DOOR_ACK_REMOTE_UNLOCK;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x1c:
	{
		// 2.10 图传设置
		// AA 55 1C 00 00 00 00 00 00 1B
		// AA 55 1D 00 00 00 00 00 00 1C
		// tprintf("get cmd: BKWL_CMD_DOOR_UPLOAD_IMAGE \n");
		msg.cmd = BKWL_CMD_DOOR_UPLOAD_IMAGE;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x20:
	{
		// 2.11 用户验证
		// AA 55 20 09 1C BB D5 5E 50 02 12 34 56 20
		// AA 55 21 05 00 00 02 02 04 2D
		// AA 55 03 01 00 02 02 04 00 0B
		// AA 55 02 00 00 00 00 00 00 01

		// tprintf("get cmd: BKWL_CMD_DOOR_USER_VERIFY \n");
		bkwl_door_user_verify_t *bkwl_door_user_verify = (bkwl_door_user_verify_t *)malloc(sizeof(bkwl_door_user_verify_t));
		memcpy(bkwl_door_user_verify->utc, data + 4, 4);
		bkwl_door_user_verify->zone = data[8];
		bkwl_door_user_verify->type = data[9];
		bkwl_door_user_verify->pwd_len = data[3] - 6;
		memcpy(bkwl_door_user_verify->pwd, data + 10, bkwl_door_user_verify->pwd_len);
		msg.cmd = BKWL_CMD_DOOR_USER_VERIFY;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_user_verify;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x23: // 下发指令，门锁无信息
	{
		// 2.12 联网通知 下發
		// AA 55 23 04 67 E9 D4 5E 50 F8
		// msg.cmd = BKWL_CMD_DOOR_USER_VERIFY;
		// msg.param = cmd_value;
		// msg.data = NULL;
		// bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x24:
	{
		// 2.13 串口图传开启
		// AA 55 24 00 0A A4 76 B0 99 90
		// AA 55 25 00 0A 00 00 00 00 2E
		// AA 55 27 00 00 A4 76 B0 99 89
		// tprintf("get cmd: BKWL_CMD_DOOR_START_UPLOAD_IMAGE \n");
		bkwl_door_setup_image_upload_t *bkwl_door_setup_image_upload = (bkwl_door_setup_image_upload_t *)malloc(sizeof(bkwl_door_setup_image_upload_t));
		bkwl_door_setup_image_upload->baudrate = data[4];
		bkwl_door_setup_image_upload->image_size = (data[6] << 8) + data[5];
		bkwl_door_setup_image_upload->verify_value = (data[8] << 8) + data[7];
		msg.cmd = BKWL_CMD_DOOR_START_UPLOAD_IMAGE;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_setup_image_upload;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x27: // 下发指令，门锁无信息
	{
		// 2.14 串口图传结果
		// AA 55 24 00 0A A4 76 B0 99 90
		// AA 55 25 00 0A 00 00 00 00 2E
		// AA 55 27 00 00 A4 76 B0 99 89
		break;
	}
	case 0x3a:
	{
		// 2.15 视频状态通知
		// AA 55 3A 00 00 00 00 00 00 39
		// AA 55 3B 02 00 00 00 00 00 3C

		// tprintf("get cmd: BKWL_CMD_DOOR_VIDEO_STATUS_NOTIFY \n");
		msg.cmd = BKWL_CMD_DOOR_VIDEO_STATUS_NOTIFY;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x3c:
	{
		// 2.16 视频参数设置
		// AA 55 3C 01 18 00 00 00 00 54
		// AA 55 3D 00 00 00 00 00 00 3C

		// tprintf("get cmd: BKWL_CMD_DOOR_VIDEO_PARA_SETUP \n");
		bkwl_door_video_para_setup_t *bkwl_door_video_para_setup = (bkwl_door_video_para_setup_t *)malloc(sizeof(bkwl_door_video_para_setup_t));
		bkwl_door_video_para_setup->language = data[3];
		bkwl_door_video_para_setup->speaker_volume = data[4];
		bkwl_door_video_para_setup->image_rotate = data[5];
		msg.cmd = BKWL_CMD_DOOR_VIDEO_PARA_SETUP;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_video_para_setup;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x42:
	{
		// 2.17 状态上传
		// AA 55 42 0F 11 01 00 00 00 62
		// AA 55 43 00 00 00 00 00 00 42

		// tprintf("get cmd: BKWL_CMD_DOOR_STATUS_REPORT \n");
		bkwl_door_status_report_t *bkwl_door_status_report = (bkwl_door_status_report_t *)malloc(sizeof(bkwl_door_status_report_t));
		bkwl_door_status_report->type = (data[4] << 8) + data[3];
		bkwl_door_status_report->value = (data[8] << 24) + (data[7] << 16) + (data[6] << 8) + data[5];
		msg.cmd = BKWL_CMD_DOOR_STATUS_REPORT;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_status_report;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x1a:
	{
		// 2.18 配网退出
		// AA 55 1A 00 00 00 00 00 00 19
		// AA 55 1B 00 00 00 00 00 00 1A

		// tprintf("get cmd: BKWL_CMD_DOOR_STOP_WIFI_PAIR \n");
		msg.cmd = BKWL_CMD_DOOR_STOP_WIFI_PAIR;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x44:
	{
		// 2.19 缓存消息上传
		// AA 55 44 09 0C 8A 90 62 01 00 03 02 00 DA
		// AA 55 45 00 00 00 00 00 00 44

		// tprintf("get cmd: BKWL_CMD_DOOR_CACHE_MESSAGE \n");
		bkwl_door_cache_message_t *bkwl_door_cache_message = (bkwl_door_cache_message_t *)malloc(sizeof(bkwl_door_cache_message_t));
		bkwl_door_cache_message->utc = (data[7] << 24) + (data[6] << 16) + (data[5] << 8) + data[54];
		bkwl_door_cache_message->event = data[8];
		bkwl_door_cache_message->info = data[9];
		bkwl_door_cache_message->user_type = data[10];
		bkwl_door_cache_message->user_num = (data[12] << 8) + data[11];
		msg.cmd = BKWL_CMD_DOOR_CACHE_MESSAGE;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_cache_message;
		bkwl_event_send_uart_door(&msg);

		//     uint32_t utc;
		//     uint8_t event;
		//     uint8_t info;
		//     uint8_t user_type;
		//     uint16_t user_num;
		// } bkwl_door_cache_message_t;

		break;
	}
	case 0x46:
	{
		// 2.20 设备功能
		// AA 55 46 00 00 00 00 00 00 45
		// AA 55 47 01 03 00 00 00 00 4A

		// tprintf("get cmd: BKWL_CMD_DOOR_DEVICE_FUNC \n");
		msg.cmd = BKWL_CMD_DOOR_DEVICE_FUNC;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x48:
	{
		// 2.21 主动查看设置
		// AA 55 48 01 00 1E 00 00 00 66
		// AA 55 49 00 00 00 00 00 00 48

		// tprintf("get cmd: BKWL_CMD_DOOR_LOOK_SETUP \n");
		bkwl_door_look_setup_t *bkwl_door_look_setup = (bkwl_door_look_setup_t *)malloc(sizeof(bkwl_door_look_setup_t));
		bkwl_door_look_setup->look = data[3];
		bkwl_door_look_setup->wakeup_label = data[4];
		bkwl_door_look_setup->wakeup_time = data[5];

		msg.cmd = BKWL_CMD_DOOR_LOOK_SETUP;
		msg.param = cmd_value;
		msg.data = (uint8_t *)bkwl_door_look_setup;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x4a:
	{
		// 2.22 版本信息
		// AA 55 4A 00 00 00 00 00 00 49
		// AA 55 4B 01 0B 00 61 00 00 B7
		// tprintf("get cmd: BKWL_CMD_DOOR_GET_VERSION \n");
		msg.cmd = BKWL_CMD_DOOR_GET_VERSION;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);

		break;
	}
	case 0x4c:
	{
		// 2.23 天气信息
		// AA 55 4C 00 00 00 00 00 00 4B
		// AA 55 4D 19 01 00 0F 01 1C 5D 16 03 14 00 EE 03 04 02 58 02 DC 50 04 05 00 03 02 02 20 64 2C
		// tprintf("get cmd: BKWL_CMD_DOOR_GET_WEATHER \n");
		msg.cmd = BKWL_CMD_DOOR_GET_WEATHER;
		msg.param = cmd_value;
		msg.data = (uint8_t *)(intptr_t)data[3];
		bkwl_event_send_uart_door(&msg);
		break;
	}
	case 0x4e:
	{
		// 2.24 地区信息
		// AA 55 4E 00 00 00 00 00 00 4D
		// AA 55 4F 2A 16 53 09 00 00 EA
		// tprintf("get cmd: BKWL_CMD_DOOR_GET_REGION \n");
		msg.cmd = BKWL_CMD_DOOR_GET_REGION;
		msg.param = cmd_value;
		msg.data = NULL;
		bkwl_event_send_uart_door(&msg);
		break;
	}
	}

	return ret;
}

bkwl_err_t bkwl_protocol_jiwei_door_ack(uint8_t cmd, uint8_t status, uint8_t ack_cmd)
{
	bkwl_err_t ret = BK_OK;
	uint8_t data_buf[BKWL_JIWEI_CMD_LEN] = {0xAA, 0x55, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
	uint32_t check_value = 0;
	data_buf[2] = cmd;
	data_buf[3] = status;
	data_buf[4] = ack_cmd;
	for (uint8_t i = 0; i < BKWL_JIWEI_CMD_LEN; i++)
	{
		check_value = check_value + data_buf[i];
	}
	data_buf[9] = (check_value & 0xff);
	tprintf("ack data: ");
	for (int i = 0; i < BKWL_JIWEI_CMD_LEN; i++)
	{
		tprintf("%02x ", (data_buf[i] & 0xff));
	}
	tprintf("\n\n\n");
	bkwl_uart_write(BKWL_IOT_DOORBELL_UART_ID, (uint8_t *)data_buf, BKWL_JIWEI_CMD_LEN);

	return ret;
}
bkwl_err_t bkwl_protocol_init_door_queue(beken_queue_t queue)
{
	bkwl_err_t ret = BKWL_OK;
	tprintf("bkwl_protocol_init_door_queue entry\n\n");
	bkwl_main->queue.uart_door = queue;
	tprintf("bkwl_protocol_init_door_queue exit\n\n");
	return ret;
}